home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / ShpTrakr.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.5 KB  |  323 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ShpTrakr.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef SHPTRAKR_H
  15. #include "ShpTrakr.h"
  16. #endif
  17.  
  18. #ifndef UTILS_H
  19. #include "Utils.h"
  20. #endif
  21.  
  22. #ifndef DRAWFRM_H
  23. #include "DrawFrm.h"
  24. #endif
  25.  
  26. #ifndef BASESHP_H
  27. #include "BaseShp.h"
  28. #endif
  29.  
  30. #ifndef BOUNDSHP_H
  31. #include "BoundShp.h"
  32. #endif
  33.  
  34. #ifndef LINESHP_H
  35. #include "LineShp.h"
  36. #endif
  37.  
  38. #ifndef OVALSHP_H
  39. #include "OvalShp.h"
  40. #endif
  41.  
  42. #ifndef RECTSHP_H
  43. #include "RectShp.h"
  44. #endif
  45.  
  46. #ifndef RRECTSHP_H
  47. #include "RRectShp.h"
  48. #endif
  49.  
  50. #ifndef TEXTSHP_H
  51. #include "TextShp.h"
  52. #endif
  53.  
  54. #ifndef DRAWVIEW_H
  55. #include "DrawView.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWCONTXT_H
  61. #include "FWContxt.h"
  62. #endif
  63.  
  64. #ifndef FWSCROLR_H
  65. #include "FWScrolr.h"
  66. #endif
  67.  
  68. #ifndef FWUTIL_H
  69. #include "FWUtil.h"
  70. #endif
  71.  
  72. #ifndef FWVIEW_H
  73. #include "FWView.h"
  74. #endif
  75.  
  76. #ifndef FWFRAME_H
  77. #include "FWFrame.h"
  78. #endif
  79.  
  80. // ----- OS Layer -----
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. //========================================================================================
  87. // Runtime Information
  88. //========================================================================================
  89.  
  90. #ifdef FW_BUILD_MAC
  91. #pragma segment odfdraw
  92. #endif
  93.  
  94. //========================================================================================
  95. //    class CShapeTracker
  96. //========================================================================================
  97.  
  98. //----------------------------------------------------------------------------------------
  99. //    CShapeTracker::CShapeTracker
  100. //----------------------------------------------------------------------------------------
  101.  
  102. CShapeTracker::CShapeTracker(Environment* ev, FW_CView* view, ODFacet* facet, CBaseShape* theShape, FW_Boolean gridOn) :
  103.     FW_CTracker(ev, view, facet),
  104.     fShape(theShape),
  105.     fErase(FALSE),
  106.     fGridOn(gridOn),
  107.     fScroller(view->GetFrame(ev)->GetScroller(ev))
  108. {
  109. }
  110.  
  111. //----------------------------------------------------------------------------------------
  112. //    CShapeTracker::~CShapeTracker
  113. //----------------------------------------------------------------------------------------
  114.  
  115. CShapeTracker::~CShapeTracker()
  116. {
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. //    CShapeTracker::BeginTracking
  121. //----------------------------------------------------------------------------------------
  122.  
  123. FW_CPoint CShapeTracker::BeginTracking(Environment* ev, 
  124.                                     const FW_CPoint& anchorPoint)
  125. {
  126.     FW_CPoint point(anchorPoint);
  127.     ForceToGrid(ev, point);
  128.     
  129.     fScroller->InitializeAutoScroll(ev);
  130.     
  131.     return point;
  132. }
  133.  
  134. //----------------------------------------------------------------------------------------
  135. //    CShapeTracker::ContinueTracking
  136. //----------------------------------------------------------------------------------------
  137.  
  138. FW_CPoint CShapeTracker::ContinueTracking(Environment* ev,
  139.                                         const FW_CPoint& anchorPoint, 
  140.                                         const FW_CPoint& previousPoint, 
  141.                                         const FW_CPoint& currentPoint)
  142. {
  143.     FW_CPoint curLoc(currentPoint);
  144.     
  145.     ForceToGrid(ev, curLoc);
  146.     
  147.     if (previousPoint != curLoc)
  148.     {
  149.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  150.         
  151.         if (fErase)
  152.             fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, previousPoint, TRUE);
  153.  
  154.         fScroller->AutoScroll(ev, currentPoint, &vc);
  155.  
  156.         fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, curLoc, FALSE);
  157.         
  158.         fErase = TRUE;
  159.     }
  160.     
  161.     return curLoc;
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. //    CShapeTracker::EndTracking
  166. //----------------------------------------------------------------------------------------
  167.  
  168. FW_Boolean CShapeTracker::EndTracking(Environment* ev,
  169.                                     const FW_CPoint& anchorPoint, 
  170.                                     const FW_CPoint& lastPoint)
  171. {
  172.     if (fErase)
  173.     {
  174.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  175.         
  176.         fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, lastPoint, TRUE);
  177.     }
  178.     
  179.     return anchorPoint != lastPoint;
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. //    CShapeTracker::ForceToGrid
  184. //----------------------------------------------------------------------------------------
  185.  
  186. void CShapeTracker::ForceToGrid(Environment* ev, FW_CPoint& point)
  187. {
  188. FW_UNUSED(ev);
  189.     if (fGridOn)
  190.     {
  191.         point.x = FW_IntToFixed((FW_FixedToInt(point.x) + 5) / 8 * 8);
  192.         point.y = FW_IntToFixed((FW_FixedToInt(point.y) + 5) / 8 * 8);
  193.     }
  194. }
  195.  
  196. //========================================================================================
  197. //    class CResizeTracker
  198. //========================================================================================
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    CResizeTracker::CResizeTracker
  202. //----------------------------------------------------------------------------------------
  203.  
  204. CResizeTracker::CResizeTracker(Environment* ev,
  205.                                 FW_CView* view, ODFacet* facet, 
  206.                                 CBaseShape* theShape, short whichHandle,
  207.                                 const FW_CInk& resizeInk, const FW_CStyle& resizeStyle,
  208.                                 FW_Boolean gridOn) :
  209.     FW_CTracker(ev, view, facet),
  210.     fShape(theShape),
  211.     fWhichHandle(whichHandle),
  212.     fResizeInk(resizeInk),
  213.     fResizeStyle(resizeStyle),
  214.     fErase(FALSE),
  215.     fGridOn(gridOn),
  216.     fScroller(view->GetFrame(ev)->GetScroller(ev))
  217. {
  218. }
  219.  
  220. //----------------------------------------------------------------------------------------
  221. //    CResizeTracker::~CResizeTracker
  222. //----------------------------------------------------------------------------------------
  223.  
  224. CResizeTracker::~CResizeTracker()
  225. {
  226. }
  227.  
  228. //----------------------------------------------------------------------------------------
  229. //    CResizeTracker::BeginTracking
  230. //----------------------------------------------------------------------------------------
  231.  
  232. FW_CPoint CResizeTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
  233. {
  234.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  235.     
  236.     FW_Fixed handleSize = CalcHandlePenSize(((CDrawFrame*)GetView(ev)->GetFrame(ev))->GetZoomFactor());
  237.     
  238.     FW_CRectShape handle(FW_kZeroRect, FW_kFill);
  239.     handle.SetInk(FW_kInvertInk);
  240.     fShape->CalcHandle(fWhichHandle, &handle, handleSize);
  241.     handle.Render(vc);    // redraw the handle
  242.  
  243.     FW_CPoint point(anchorPoint);
  244.     ForceToGrid(ev, point);
  245.     
  246.     FW_CPoint handleCenter;
  247.     fShape->GetHandleCenter(fWhichHandle, handleCenter);
  248.     fDelta = point - handleCenter;
  249.  
  250.     fScroller->InitializeAutoScroll(ev);
  251.     
  252.     return handleCenter;
  253. }
  254.  
  255. //----------------------------------------------------------------------------------------
  256. //    CResizeTracker::ContinueTracking
  257. //----------------------------------------------------------------------------------------
  258.  
  259. FW_CPoint CResizeTracker::ContinueTracking(Environment* ev,
  260.                                             const FW_CPoint& anchorPoint, 
  261.                                             const FW_CPoint& previousPoint, 
  262.                                             const FW_CPoint& currentPoint)
  263. {
  264. FW_UNUSED(anchorPoint);
  265.  
  266.     // ----- Adjust for the size of the handle
  267.     FW_CPoint curLoc(currentPoint - fDelta);        
  268.     ForceToGrid(ev, curLoc);
  269.  
  270.     if (previousPoint != curLoc)
  271.     {
  272.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  273.     
  274.         if (fErase)
  275.             fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, previousPoint);        // erase
  276.                 
  277.         fScroller->AutoScroll(ev, currentPoint, &vc);
  278.  
  279.         fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, curLoc);            // draw
  280.         
  281.         fErase = TRUE;                
  282.     }
  283.     
  284.     return curLoc;
  285. }
  286.  
  287. //----------------------------------------------------------------------------------------
  288. //    CResizeTracker::EndTracking
  289. //----------------------------------------------------------------------------------------
  290.  
  291. FW_Boolean CResizeTracker::EndTracking(Environment* ev,
  292.                                     const FW_CPoint& anchorPoint, 
  293.                                     const FW_CPoint& lastPoint)
  294. {
  295. FW_UNUSED(anchorPoint);
  296.  
  297.     fLastLocation = lastPoint - fDelta;
  298.     ForceToGrid(ev, fLastLocation);
  299.     
  300.     if (fErase)
  301.     {
  302.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  303.     
  304.         fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, fLastLocation);
  305.     }
  306.     
  307.     return anchorPoint != lastPoint;
  308. }
  309.  
  310. //----------------------------------------------------------------------------------------
  311. //    CResizeTracker::ForceToGrid
  312. //----------------------------------------------------------------------------------------
  313.  
  314. void CResizeTracker::ForceToGrid(Environment* ev, FW_CPoint& point)
  315. {
  316. FW_UNUSED(ev);
  317.     if (fGridOn)
  318.     {
  319.         point.x = FW_IntToFixed((FW_FixedToInt(point.x) + 5) / 8 * 8);
  320.         point.y = FW_IntToFixed((FW_FixedToInt(point.y) + 5) / 8 * 8);
  321.     }
  322. }
  323.